import { validateBase } from "@/utils/api";
import { Router as R } from "express";
import type { Router } from "express";
import { queryUserParamsConfig } from "./params-config";
// import { logger } from "@/utils/log"; // 日志方法
// import { execute } from "@/utils/mysql/index"; // 执行数据库方法
// import { executeCommand } from "@/utils/api";
// import { setKeyValue } from "@/utils/redis";
// import type { UserInfo } from "./typing";
// import { setToken } from "@/utils/token";
import { response } from "@/utils/api";
const router: Router = R();

router.get("", (req, res) => {
  // 调用参数校验方法
  const validate = validateBase(queryUserParamsConfig, req.query.userId);
  if (validate) return response(res, 205, validate);
  response(res, 200);
});

// 登录获取用户信息-生成token
// router.get("/login", (req, res) =>
//   executeCommand(req, res, async () => {
//     // 验证用户名以及密码等。
//     const data = await execute<UserInfo>(
//       "select * from user where username = ? and password = ?",
//       [req.body.username, req.body.password]
//     );
//     const [user] = data;
//     if (!user) return logger.error({ message: "用户名或密码错误", res });
//     // 生成token
//     const token = setToken({ userId: user.username });
//     // redis存储
//     setKeyValue(token, user);
//     // 响应
//     response(res, 200, { token });
//   })
// );

export default router;
